package Server;

import java.util.Hashtable;
import java.util.Vector;

import org.gibello.zql.*;

public class MyParser {
	int type;// loại truy vấn (1: select,2:insert,3:update,4:delete)
	ZStatement statement;// câu truy vấn

	public MyParser(int type, ZStatement statement) {
		this.type = type;
		this.statement = statement;
	}
	public int getType() {
		return type;
	}
	public void setType(int type) {
		this.type = type;
	}
	public void setStatement(ZStatement statement) {
		this.statement = statement;
	}
	public ZStatement getStatement() {
		return statement;
	}
	Vector getSelect() {
		ZQuery q = null;
		Vector v = null;
		if (type == 1) {
			q = (ZQuery) statement;
			v = q.getSelect();
		}
		return v;
	}

	Vector getFrom() {
		
		Vector v = null;
		if (type == 1) // select 
		{
			ZQuery q = (ZQuery) statement;
			v = q.getFrom();
		}
		if(type == 2) //insert
		{
			ZInsert q = (ZInsert) statement;
			String tableName = q.getTable();
			v = new Vector();
			v.add(tableName);
		}
		if(type ==3) //update
		{
			ZUpdate q =(ZUpdate) statement;
			String tableName = q.getTable();
			v = new Vector();
			v.add(tableName);
		}
		if(type == 4) // delete
		{
			ZDelete q = (ZDelete) statement;
			String tableName = q.getTable();
			v = new Vector();
			v.add(tableName);
		}
		return v;
	}
	Vector getValue()
	{
		Vector value = null;
		if(type==2)//insert
		{
			ZInsert q = (ZInsert) statement;		
			value = q.getValues();		
		}
		return value;
	}
	Vector getOperands()
	{
		Vector v = null;
		if(type == 1)// select 
		{
			ZQuery q = (ZQuery)statement;
			ZExpression tempExp = (ZExpression)q.getWhere();
			v = tempExp.getOperands();						
		}
		if(type == 3)//insert
		{
			ZUpdate q = (ZUpdate)statement;
			ZExpression tempExp = (ZExpression)q.getWhere();
			v = tempExp.getOperands();						
		}
		if(type == 4)//delete
		{
			ZDelete q = (ZDelete) statement;
			ZExpression tempExp = (ZExpression)q.getWhere();
			v = tempExp.getOperands();						
		}
		return v;
	}
	ZExpression getWhere()
	{
		ZExpression tempExp = null ;
		if(type == 1)// select 
		{
			ZQuery q = (ZQuery)statement;
			tempExp = (ZExpression)q.getWhere();							
		}
		if(type == 3)//update
		{
			ZUpdate q = (ZUpdate)statement;
			tempExp = (ZExpression)q.getWhere();							
		}	
		if(type == 4)// delete 
		{
			ZDelete q = (ZDelete)statement;
			tempExp = (ZExpression)q.getWhere();							
		}
		return tempExp;
	}
	String getOperator()
	{
		String result = null;
		if(type == 4)//delete
		{
			ZDelete q = (ZDelete) statement;
			ZExpression tempExp = (ZExpression)q.getWhere();
			
			result = tempExp.getOperator();		
		}
		return result;		
	}
	Hashtable getSet()
	{
		Hashtable ht = null;
		if(type == 3)//insert
		{
			ZUpdate q = (ZUpdate)statement;
			ht = q.getSet();
		}
		return ht;
	}
	ZGroupBy getGroupBy()
	{
		ZGroupBy group = null;
		if(type == 1)//select
		{
			ZQuery q = (ZQuery)statement;
			group = q.getGroupBy();
		}
		return group;
	}

}
